package cn.qinhao.pethome.basic.base.service.impl;

import cn.qinhao.pethome.basic.base.mapper.BaseMapper;
import cn.qinhao.pethome.basic.base.query.BaseQuery;
import cn.qinhao.pethome.basic.base.service.IBaseService;
import cn.qinhao.pethome.basic.until.PageList;
import cn.qinhao.pethome.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public void add(T t) {
        baseMapper.add(t);

    }

    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public T selectOne(Long id) {
        return baseMapper.selectOne(id);
    }

    @Override
    public List<T> selectAll() {
        return baseMapper.selectAll();
    }

    @Override
    public PageList<T> pageQuery(BaseQuery query) {

        //创建封装结果对象
        Long total = baseMapper.queryCount(query);
        List<T> list = baseMapper.queryData(query);
        PageList<T> departmentPageList = new PageList<>(total, list);

        return departmentPageList;
    }

    @Override
    public void batchDelete(List<Long> ids) {
        baseMapper.batchRemove(ids);
    }
}
